package com.etang.homeproject2.tools;

import ohos.app.Context;
import ohos.data.DatabaseHelper;
import ohos.data.rdb.RdbOpenCallback;
import ohos.data.rdb.RdbStore;
import ohos.data.rdb.StoreConfig;

public class SQLHelper {

    public static void initPreferences(Context context) {

    }

    public static void initSQL(Context context) {
        //设置数据库为RdbStore.db
        StoreConfig config = StoreConfig.newDefaultConfig("info.db");
        DatabaseHelper helper = new DatabaseHelper(context);
        RdbStore rdbStore = helper.getRdbStore(config, 1, new RdbOpenCallback() {
            @Override
            public void onCreate(RdbStore rdbStore) {
                rdbStore.executeSql("create table if not exists user(userId integer primary key autoincrement,userName text)");
                rdbStore.executeSql("create table if not exists first_open(userId integer primary key autoincrement,isopen text)");

            }

            @Override
            public void onUpgrade(RdbStore rdbStore, int i, int i1) {
                //升级数据库操作
            }
        });
    }
}
